#ifndef HTTP_LINK_MANAGER_H
#define HTTP_LINK_MANAGER_H
#include "escal.h"
#include "file_manager.h"
#include "link_manager.h"
#include <QThread>
#include <QHttp>
#include <QUrl>

class QThread;
class QUrl;
class QHttp;

class HttpLinkManager:public BaseLinkManager{
	Q_OBJECT
public:
	HttpLinkManager(FileManager *fileManager, const QUrl &url,
		QObject *parent=0);
	~HttpLinkManager();
	void stop();
signals:
	//void linkQuit();
	void linkQuited(BaseLinkManager *link, bool error);
	void serverAcceptRanges();
protected:
	void cleanUp();
	void run();
protected slots:
	void startDownload();
	void stopDownload();
	void readResponseHeader(const QHttpResponseHeader &responseHeader);
	//void fileManagerQuited();
	void httpRequestDone(bool error);
	void readResponseData( const QHttpResponseHeader & responseHeader); 
	void updateDataReadProgress(int bytesRead, int totalBytes);
private:
	FileManager *fileManager;
	QUrl url;
	QHttp http;
	int pieceIndex;
	qint64 offset;
	int httpGetId;
	int status;
	bool reconnect;
	bool quit;
	bool gotPiece;
};
#endif /* HTTP_LINK_MANAGER_H */
